package com.wise.wing.activity.order;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;




import com.android.volley.VolleyError;
import com.bm.corelibs.logic.BaseLogic.NListener;
import com.bm.corelibs.utils.ToastMgr;
import com.bm.corelibs.utils.ViewHolder;
import com.bm.corelibs.views.FlexibleRatingBar;
import com.makeramen.roundedimageview.RoundedTransformationBuilder;
import com.squareup.picasso.Picasso;
import com.wise.wing.R;
import com.wise.wing.activity.logic.LoginManager;
import com.wise.wing.activity.logic.ServiceLogManager;
import com.wise.wing.activity.main.BaseActivity;
import com.wise.wing.bean.BaseData;
import com.wise.wing.bean.Fee;
import com.wise.wing.bean.Feedback;
import com.wise.wing.bean.JobDetail;
import com.wise.wing.bean.Order;
import com.wise.wing.bean.OrderLog;
import com.wise.wing.bean.ServiceLog;
import com.wise.wing.bean.SumService;
import com.wise.wing.constant.Constant;
import com.wise.wing.views.CommonNavigationBar;
import com.wise.wing.views.CustomDialog;
import com.wise.wing.views.RaitingBarForShowing;
import com.wise.wing.views.SimpleListView;

public class OwnerDetailActivity extends BaseActivity implements OnClickListener {

	public static final String ORDER = "ORDER";
	public static final String OWNER = "OWNER";

	private CommonNavigationBar navi;
	private View v_divider, v_divider2;
	private RelativeLayout rl_empty;
	private TextView tv_empty, tv_name, tv_licenseplateNum, tv_style, tv_owner_status, tv_reason, tv_price, tv_volume, tv_content;
	private Button btn_close, btn_one_sign, btn_submit, btn_one_check;
	private ImageView iv_icon, iv_tel;
	private LinearLayout ll_cancel, ll_evaluate, ll_logs;
	private ListView lv_logs;
	private RaitingBarForShowing ratingbar;
	private FlexibleRatingBar rb_rating;
	private EditText et_content;

	private Order order;
	private OrderLog ol;
	private JobDetail detail;
	private LogsAdapter adapter = new LogsAdapter();
	private CustomDialog dialog;
	private ServiceLogManager manager = new ServiceLogManager();
	private boolean isShowSignbox = false;
	private boolean isShowCheckbox = false;
	private SparseBooleanArray checkStatus;
	private String content;
	private float score = 0;
	private List<ServiceLog> tmpLogs;
	private SumService sumService;
	private Feedback feedback;

	private Runnable refresh = new Runnable() {
		@Override
		public void run() {
			manager.getOwnerDetail(ol.id, ol.ownerId, order.id, getListener());
			mHandler.postDelayed(refresh, Constant.REFRESH_TIME);
		}
	};

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mHandler.removeCallbacks(refresh);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_owner_detail);
		findViews();
		init();
		addListeners();
	}

	@Override
	public void findViews() {
		navi = (CommonNavigationBar) findViewById(R.id.navi);
		v_divider = (View) findViewById(R.id.v_divider);
		v_divider2 = (View) findViewById(R.id.v_divider2);
		rl_empty = (RelativeLayout) findViewById(R.id.rl_empty);
		tv_name = (TextView) findViewById(R.id.tv_name);
		tv_empty = (TextView) findViewById(R.id.tv_empty);
		ratingbar = (RaitingBarForShowing) findViewById(R.id.ratingbar);
		tv_licenseplateNum = (TextView) findViewById(R.id.tv_licenseplateNum);
		tv_style = (TextView) findViewById(R.id.tv_style);
		tv_owner_status = (TextView) findViewById(R.id.tv_owner_status);
		btn_close = (Button) findViewById(R.id.btn_close);
		iv_icon = (ImageView) findViewById(R.id.iv_icon);
		iv_tel = (ImageView) findViewById(R.id.iv_tel);
		tv_reason = (TextView) findViewById(R.id.tv_reason);
		ll_cancel = (LinearLayout) findViewById(R.id.ll_cancel);
		ll_evaluate = (LinearLayout) findViewById(R.id.ll_evaluate);
		lv_logs = (ListView) findViewById(R.id.lv_logs);
		ll_logs = (LinearLayout) findViewById(R.id.ll_logs);
		btn_one_sign = (Button) findViewById(R.id.btn_one_sign);
		tv_price = (TextView) findViewById(R.id.tv_price);
		tv_volume = (TextView) findViewById(R.id.tv_volume);
		rb_rating = (FlexibleRatingBar) findViewById(R.id.rb_rating);
		btn_submit = (Button) findViewById(R.id.btn_submit);
		et_content = (EditText) findViewById(R.id.et_content);
		tv_content = (TextView) findViewById(R.id.tv_content);
		btn_one_check = (Button) findViewById(R.id.btn_one_check);
	}

	@Override
	public void init() {
		navi.setTitle(R.string.owner_detail);
		navi.setListener(null);
		initRatingbar();
		order = (Order) getIntent().getSerializableExtra(ORDER);
		ol = (OrderLog) getIntent().getSerializableExtra(OWNER);
		dialog = new CustomDialog(mActivity);
		loadingDialog.show();
		manager.getOwnerDetail(ol.id, ol.ownerId, order.id, getListener());
		mHandler.postDelayed(refresh, Constant.REFRESH_TIME);
	}

	private void initRatingbar() {
		rb_rating.setColorFillOn(0xffffd200);
		rb_rating.setColorFillOff(0xffdad9d9);
		rb_rating.setStrokeWidth(0);
		rb_rating.setColorOutlineOn(0x00000000);
		rb_rating.setColorOutlinePressed(0x00000000);
		rb_rating.setColorOutlineOff(0x00000000);
		rb_rating.setColorFillPressedOn(0xffffd200);
		rb_rating.setColorFillPressedOff(0xffdad9d9);
	}

	private NListener<BaseData> getListener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				loadingDialog.dismiss();
				if (data.status == Constant.STATUS_OK) {
					if (data.data.orderLog != null) {
						detail = data.data.orderLog;
						sumService = data.data.sumService;
						feedback = data.data.feedback;
						ol.statusId = detail.statusId;
						setOwnerData();
					}
				} else {
					ToastMgr.show(data.msg);
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

	private NListener<BaseData> getEvListener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				loadingDialog.dismiss();
				if (data.status == Constant.STATUS_OK) {
					tv_content.setText(content);
					rb_rating.setRating(score);
					showEvaluateContent();
					ToastMgr.show(R.string.owner_detail_msg4);
				} else {
					ToastMgr.show(data.msg);
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

	private NListener<BaseData> getCloseistener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				loadingDialog.dismiss();
				if (data.status == Constant.STATUS_OK) {
					ToastMgr.show(R.string.owner_detail_msg1);
					setResult(RESULT_OK);
					finish();
				} else {
					ToastMgr.show(data.msg);
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

	private void setOwnerData() {
		tv_name.setText(ol.driver);
		tv_licenseplateNum.setText(ol.licensePlate + ol.licensePlateNum);
		ratingbar.setRate(ol.averageScore);
		tv_style.setText(ol.style1 + ":" + ol.styleName);
		Picasso.with(mActivity).load(ol.icon).resize(480, 480).centerCrop().transform(new RoundedTransformationBuilder().oval(true).build()).into(iv_icon);

		int id = detail.statusId;

		// if (order.status == 2 || order.status == 3) {
		tv_owner_status.setVisibility(View.VISIBLE);
		tv_owner_status.setText(ol.getStatusMsg(id));
		// } else {
		// tv_owner_status.setVisibility(View.INVISIBLE);
		// }

		// 未开始
		if (id == 1 || id == 2 || id == 3 || id == 4) {
			hideLogList();
			tv_empty.setText(R.string.owner_detail_hint1);
		}
		// 已开始, 无服务记录
		else if (id == 6) {
			hideLogList();
			tv_empty.setText(R.string.owner_detail_hint2);
		}
		// 已开始, 有服务记录
		else if (id == 7 || id == 8 || id == 15) {
			if (detail == null || detail.serviceLogs == null || detail.serviceLogs.size() <= 0) {
				hideLogList();
				tv_empty.setText(R.string.owner_detail_hint2);
			} else {
				showLogList();
				lv_logs.setAdapter(adapter);
			}
		}
		// 已完成, 待评价
		else if (id == 9) {
			showEvaluate();
			tv_price.setText("¥" + (sumService == null ? 0 : sumService.realSumPrice));
			tv_volume.setText((sumService == null ? 0 : sumService.volume) + "");
			rb_rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
				@Override
				public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
					btn_submit.setVisibility(View.VISIBLE);
					et_content.setVisibility(View.VISIBLE);
				}
			});
		}
		// 已完成, 已评价
		else if (id == 10) {
			showEvaluateContent();
			rb_rating.setEnabled(false);
			tv_price.setText("¥" + (sumService == null ? 0 : sumService.realSumPrice));
			tv_volume.setText((sumService == null ? 0 : sumService.volume) + "方");
			if (feedback != null) {
				rb_rating.setRating(feedback.score / 2);
				tv_content.setText(feedback.content);
			}
		}
		// 已取消
		else if (id == 5 || id == 11 || id == 12) {
			showCancelReason();
		}
		// 其他
		else {
		}

		if (id == 2 || id == 3 || id == 4 || id == 6)
			btn_close.setVisibility(View.VISIBLE);
		else
			btn_close.setVisibility(View.GONE);

		int signCount = 0, checkCount = 0;
		for (int i = 0; i < detail.serviceLogs.size(); i++) {
			if (detail.serviceLogs.get(i).status == 0)
				signCount++;
			
			if (detail.serviceLogs.get(i).status == 1)
				checkCount++;
		}

		if (signCount <= 0) {
			btn_one_sign.setVisibility(View.GONE);
			if(checkCount <= 0) {
				btn_one_check.setVisibility(View.GONE);
			} else {
				btn_one_check.setVisibility(View.VISIBLE);
			}
		} else {
			btn_one_sign.setVisibility(View.VISIBLE);
			btn_one_check.setVisibility(View.GONE);
		}
	}

	private void hideLogList() {
		showTipsLayout();
		ll_logs.setVisibility(View.GONE);
	}

	private void showLogList() {
		rl_empty.setVisibility(View.GONE);
		v_divider2.setVisibility(View.GONE);
		v_divider.setVisibility(View.VISIBLE);
		ll_logs.setVisibility(View.VISIBLE);
	}

	private void showEvaluate() {
		rl_empty.setVisibility(View.GONE);
		v_divider2.setVisibility(View.GONE);
		v_divider.setVisibility(View.VISIBLE);
		ll_evaluate.setVisibility(View.VISIBLE);
		tv_content.setVisibility(View.GONE);
		ll_logs.setVisibility(View.GONE);
	}

	private void showEvaluateContent() {
		rl_empty.setVisibility(View.GONE);
		v_divider2.setVisibility(View.GONE);
		v_divider.setVisibility(View.VISIBLE);
		ll_evaluate.setVisibility(View.VISIBLE);
		tv_content.setVisibility(View.VISIBLE);
		btn_submit.setVisibility(View.GONE);
		et_content.setVisibility(View.GONE);
		rb_rating.setEnabled(false);
	}

	private void showCancelReason() {
		showTipsLayout();
		ll_cancel.setVisibility(View.VISIBLE);
		if (detail.reason != null && detail.reason.length() > 0)
			tv_reason.setText(detail.reason);
		if (detail.otherReason != null && detail.otherReason.length() > 0)
			tv_reason.setText(detail.otherReason);
		btn_close.setEnabled(false);
	}

	private void showTipsLayout() {
		rl_empty.setVisibility(View.VISIBLE);
		v_divider2.setVisibility(View.VISIBLE);
		v_divider.setVisibility(View.GONE);
	}

	@Override
	public void addListeners() {
		iv_tel.setOnClickListener(this);
		btn_close.setOnClickListener(this);
		btn_one_sign.setOnClickListener(this);
		btn_submit.setOnClickListener(this);
		btn_one_check.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_close:
			dialog.show();
			dialog.justShowMsg(R.string.owner_detail_hint9, new OnClickListener() {
				@Override
				public void onClick(View v) {
					dialog.dismiss();
					loadingDialog.show();
					manager.closeOwner(order.id, ol.ownerId, getCloseistener());
				}
			});
			break;

		case R.id.iv_tel:
			Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ol.phone));
			startActivity(callIntent);
			break;

		// 评价
		case R.id.btn_submit:
			String content = et_content.getText().toString().trim();
			if (content.length() <= 0) {
				content = " ";
			}

			if (content.length() > 200) {
				ToastMgr.show(R.string.owner_detail_msg3);
				return;
			}

			score = rb_rating.getRating();
			this.content = content;
			loadingDialog.show();
			manager.evaluate(LoginManager.getInstance(mActivity).getId(), order.id, ol.ownerId, (int) (score * 2), ol.id, content, getEvListener());
			break;

		// 一键签收
		case R.id.btn_one_sign:
			tmpLogs = new ArrayList<ServiceLog>();
			if (!isShowSignbox) {
				boolean isNoOne = true;
				for (int i = 0; i < adapter.getCount(); i++) {
					if (detail.serviceLogs.get(i).status == 0)
						isNoOne = false;
				}
				if (isNoOne) {
					ToastMgr.show("暂无可签收的服务记录");
				} else {
					isShowSignbox = true;
					initSignStatus();
					adapter.notifyDataSetChanged();
					btn_one_sign.setText("确认");
				}
			} else {
				String ids = "";
				for (int i = 0; i < adapter.getCount(); i++) {
					if (checkStatus.get(i)) {
						tmpLogs.add(detail.serviceLogs.get(i));
						ids += (detail.serviceLogs.get(i).id + ",");
					}
				}

				if (tmpLogs.size() <= 0) {
					ToastMgr.show("请选择至少一条记录");
					return;
				}

				ids = ids.substring(0, ids.length() - 1);
				signLog(ids);
			}
			break;

		// 一键结算
		case R.id.btn_one_check:
			tmpLogs = new ArrayList<ServiceLog>();
			if (!isShowCheckbox) {
				boolean isNoOne = true;
				for (int i = 0; i < adapter.getCount(); i++) {
					if (detail.serviceLogs.get(i).status == 1)
						isNoOne = false;
				}
				if (isNoOne) {
					ToastMgr.show("暂无可结算的服务记录");
				} else {
					isShowCheckbox = true;
					initCheckStatus();
					adapter.notifyDataSetChanged();
					btn_one_check.setText("确认");
				}
			} else {
				for (int i = 0; i < adapter.getCount(); i++) {
					if (checkStatus.get(i)) {
						tmpLogs.add(detail.serviceLogs.get(i));
					}
				}

				if (tmpLogs.size() <= 0) {
					ToastMgr.show("请选择至少一条记录");
					return;
				}

				toCheckOutActivity(tmpLogs);
				btn_one_check.setText("一键结算");
				isShowCheckbox = false;
				adapter.notifyDataSetChanged();
			}
			break;
		}
	}

	private void signLog(String ids) {
		loadingDialog.show();
		manager.sign(ol.ownerId + "", ol.orderId, ids, signListener());
	}

	private void toCheckOutActivity(List<ServiceLog> tmpLogs) {
		Intent intent = new Intent(OwnerDetailActivity.this, CheckOutActivity.class);
		intent.putExtra(CheckOutActivity.ORDER, order);
		intent.putExtra(CheckOutActivity.OWNER, ol);
		intent.putExtra(CheckOutActivity.SERVISE_LOGS, (Serializable) tmpLogs);
		startActivityForResult(intent, 1);
	}

	private void initSignStatus() {
		checkStatus = new SparseBooleanArray();
		for (int i = 0; i < adapter.getCount(); i++) {
			checkStatus.put(i, detail.serviceLogs.get(i).status == 0);
		}
		
		System.out.println(checkStatus.toString());
	}
	
	private void initCheckStatus() {
		checkStatus = new SparseBooleanArray();
		for (int i = 0; i < adapter.getCount(); i++) {
			checkStatus.put(i, detail.serviceLogs.get(i).status == 1);
		}
	}

	class LogsAdapter extends BaseAdapter implements OnClickListener {

		@Override
		public int getCount() {
			return detail == null || detail.serviceLogs == null ? 0 : detail.serviceLogs.size();
		}

		@Override
		public Object getItem(int position) {
			return detail.serviceLogs.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@SuppressLint("InflateParams")
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null)
				convertView = LayoutInflater.from(mActivity).inflate(R.layout.item_logs, null);

			ServiceLog log = detail.serviceLogs.get(position);

			ImageView iv_status_icon = ViewHolder.get(convertView, R.id.iv_status_icon);
			TextView tv_status_name = ViewHolder.get(convertView, R.id.tv_status_name);
			TextView tv_total = ViewHolder.get(convertView, R.id.tv_total);
			TextView tv_distance_name = ViewHolder.get(convertView, R.id.tv_distance_name);
			// TextView tv_instruction = ViewHolder.get(convertView, R.id.tv_instruction);
			TextView tv_time = ViewHolder.get(convertView, R.id.tv_time);
			TextView tv_distance = ViewHolder.get(convertView, R.id.tv_distance);
			TextView tv_volume = ViewHolder.get(convertView, R.id.tv_volume);
			TextView tv_remark = ViewHolder.get(convertView, R.id.tv_remark);
			TextView tv_unitprice = ViewHolder.get(convertView, R.id.tv_unitprice);
			Button btn_action = ViewHolder.get(convertView, R.id.btn_action);
			SimpleListView lv_fees = ViewHolder.get(convertView, R.id.lv_fees);
			CheckBox cb_check = ViewHolder.get(convertView, R.id.cb_check);

			if (isShowSignbox) {
				if (log.status == 0) {
					cb_check.setVisibility(View.VISIBLE);
					cb_check.setTag(position);
					cb_check.setOnClickListener(this);
					cb_check.setChecked(checkStatus.get(position));
				} else {
					cb_check.setVisibility(View.GONE);
				}
			} else if (isShowCheckbox) {
				if (log.status == 1) {
					cb_check.setVisibility(View.VISIBLE);
					cb_check.setTag(position);
					cb_check.setOnClickListener(this);
					cb_check.setChecked(checkStatus.get(position));
				} else {
					cb_check.setVisibility(View.GONE);
				}
			} else
				cb_check.setVisibility(View.GONE);

			iv_status_icon.setImageResource(log.getStatusIcon(log.status));
			tv_status_name.setText(log.getStatusText(log.status));
			tv_total.setText("¥" + log.realsumPrice);
			double fees = 0;
			for (int i = 0; i < log.typeCharges.size(); i++) {
				fees += log.typeCharges.get(i).charge;
			}
			tv_unitprice.setText(new java.text.DecimalFormat("0.00").format(((log.realsumPrice - fees) / log.volume)) + "元/方");
			if (log.distance == null || log.distance.length() <= 0 || log.distance.equals("null") || log.distance.equals("NULL")) {
				tv_distance_name.setVisibility(View.GONE);
				tv_distance.setVisibility(View.GONE);
			} else {
				tv_distance_name.setVisibility(View.VISIBLE);
				tv_distance.setVisibility(View.VISIBLE);
				tv_distance.setText(log.distance);
			}

			if (log.remarks == null || log.remarks.length() <= 0 || log.remarks.equals("null") || log.remarks.equals("NULL")) {
				tv_remark.setText("无");
			} else {
				tv_remark.setText(log.remarks);
			}

			tv_time.setText(log.startTime);
			tv_volume.setText(log.volume + "方");
			switch (log.status) {
			case 0:
				btn_action.setText("签收");
				btn_action.setBackgroundResource(R.drawable.btn_style);
				btn_action.setEnabled(true);
				btn_action.setOnClickListener(signListener);
				break;

			case 1:
				btn_action.setText("结算");
				btn_action.setBackgroundResource(R.drawable.btn_style);
				btn_action.setEnabled(true);
				btn_action.setOnClickListener(checkListener);
				break;

			case 2:
				btn_action.setText("已结算");
				btn_action.setBackgroundResource(R.drawable.btn_style_gray);
				btn_action.setEnabled(false);
				break;
			}
			btn_action.setTag(log);
			lv_fees.setAdapter(new FeeAdapter(log.typeCharges));
			
//			if (order.style1.equals(Constant.SPECIAL_STYLE)) {
//				tv_volume.setText(R.string.tongche + ": ");
//			} else {
//				tv_volume.setText(R.string.pumper + ": ");
//			}

			return convertView;
		}

		class FeeAdapter extends BaseAdapter {

			private List<Fee> fees;

			public FeeAdapter(List<Fee> fees) {
				this.fees = fees;
			}

			@Override
			public int getCount() {
				return fees == null ? 0 : fees.size();
			}

			@Override
			public Object getItem(int position) {
				return fees.get(position);
			}

			@Override
			public long getItemId(int position) {
				return position;
			}

			@SuppressLint("InflateParams")
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				if (convertView == null)
					convertView = LayoutInflater.from(mActivity).inflate(R.layout.item_fees, null);

				Fee fee = fees.get(position);

				TextView tv_name = ViewHolder.get(convertView, R.id.tv_name);
				TextView tv_fee = ViewHolder.get(convertView, R.id.tv_fee);

				tv_name.setText(fee.typeName + "：");
				tv_fee.setText("¥" + fee.charge);

				return convertView;
			}

		}

		OnClickListener signListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				final ServiceLog log = (ServiceLog) v.getTag();
				dialog.show();
				dialog.justShowMsg(R.string.owner_detail_hint8, new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog.dismiss();
						tmpLogs = new ArrayList<ServiceLog>();
						tmpLogs.add(log);
						signLog(log.id + "");
					}
				});
			}
		};

		OnClickListener checkListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				final ServiceLog log = (ServiceLog) v.getTag();
				// tmpLogs = new ArrayList<ServiceLog>();
				// tmpLogs.add(log);
				// toCheckOutActivity(tmpLogs);
				final CustomDialog dialog = new CustomDialog(mActivity);
				dialog.show();
				dialog.justShowMsg("结算金额: ¥" + log.realsumPrice + "\n方量: " + log.volume + "\n\n确定结算?", new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog.dismiss();
						loadingDialog.show();
						manager.checkOut(log.id + "", LoginManager.getInstance(mActivity).getUid(), ol.ownerId, ol.truckId, checkOutListener());
					}
				});
			}
		};

		@Override
		public void onClick(View v) {
			CheckBox box = (CheckBox) v;
			checkStatus.put((Integer) box.getTag(), box.isChecked());
		}
	}

	private NListener<BaseData> checkOutListener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				if (data.status == Constant.STATUS_OK) {
					ToastMgr.show(R.string.checkout_msg1);
					manager.getOwnerDetail(ol.id, ol.ownerId, order.id, getListener());
				} else if (data.status == 8) {
					loadingDialog.dismiss();
					ToastMgr.show("账户余额不足，请充值");
					//startActivity(new Intent(mActivity, RechargeMoneyActivity.class));
				} else {
					loadingDialog.dismiss();
					ToastMgr.show(data.msg);
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

	private NListener<BaseData> signListener() {
		return new NListener<BaseData>() {
			@Override
			public void onResponse(BaseData data) {
				loadingDialog.dismiss();
				if (data.status == Constant.STATUS_OK) {
					isShowSignbox = false;
					adapter.notifyDataSetChanged();
					btn_one_sign.setText(R.string.action_one_sign);
					manager.getOwnerDetail(ol.id, ol.ownerId, order.id, getListener());
//					if (isOneSign)
//						toCheckOutActivity(tmpLogs);
				} else {
					ToastMgr.show(data.msg);
				}
			}

			@Override
			public void onErrResponse(VolleyError error) {
				loadingDialog.dismiss();
			}

			@Override
			public void onAllPageLoaded(int nowPage, int totalPage) {
			}
		};
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent arg2) {
		if (resultCode == RESULT_OK) {
			loadingDialog.show();
			manager.getOwnerDetail(ol.id, ol.ownerId, order.id, getListener());
		}
	}

}
